<template>
	<view class="user-perfetion-page">
		<uni-forms ref="form" :modelValue="formData" :rules="rules" label-position="top" :label-width="200">
			<uni-forms-item label="原始密码" name="originalpassword">
				<uni-easyinput type="password" v-model="formData.originalpassword" placeholder="请输入" />
			</uni-forms-item>
			<uni-forms-item label="密码" name="password">
				<uni-easyinput type="password" v-model="formData.password" placeholder="请输入" />
			</uni-forms-item>
			<uni-forms-item label="确认密码" name="checkpassword">
				<uni-easyinput type="password" v-model="formData.checkpassword" placeholder="请输入" />
			</uni-forms-item>
			<div style='margin-top: 10rx;height: 150rpx;'></div>
			<div class="foot">
				<button class="submit" @click="submit">提交</button>
			</div>


		</uni-forms>
	</view>
</template>

<script>
	// https://ext.dcloud.net.cn/plugin?id=7446 身份证正反面上传文档
	import RboyUploadSfz from "@/components/Rboy-upload-sfz/Rboy-upload-sfz.vue"
	export default {
		data() {
			return {
				typeList: [{
					title: '蔬菜种植',
					id: 1
				}, {
					title: '蔬菜种植',
					id: 2
				}],
				index: 0,
				formData: {
					originalpassword: '',
					password: '',
					checkpassword: '',
				},
				rules: {
					originalpassword: {
						rules: [{
							required: true,
							errorMessage: '请填写原始密码',
						}, ],
						// 当前表单域的字段中文名，可不填写
						label: '原始密码',
						validateTrigger: 'submit'
					},
					password: {
						rules: [{
							required: true,
							errorMessage: '请填写密码',
						}, ],
						// 当前表单域的字段中文名，可不填写
						label: '密码',
						validateTrigger: 'submit'
					},
					checkpassword: {
						rules: [{
							required: true,
							errorMessage: '请填写确认密码',
						}, ],
						// 当前表单域的字段中文名，可不填写
						label: '密码',
						validateTrigger: 'submit'
					},
				},

			};
		},
		components: {
			RboyUploadSfz,
		},
		onReady() {
			if(!uni.getStorageSync('token')){
				uni.navigateTo({
					url:"/pages/login/login"
				})
			}
			// 需要在onReady中设置规则
			this.$refs.form.setRules(this.rules)
		},
		methods: {
			// 表单提交
			submit(form) {
				this.$refs.form.validate().then(res => {
					this.$H.post('/user/uppass', {
						form: this.formData
					}).then(res => {
						if (res.status == 500) {
							uni.showToast({
								icon: "none",
								title: res.message
							})
						}
						if (res.status == 200) {
							uni.showToast({
								icon: "success",
								title: res.message
							})
							
					
							setTimeout(() => {
								uni.switchTab({
									url: '/pages/my/my',
								})
							},2000)
						}
					})
				}).catch(err => {
					console.log('表单错误信息：', err);
				})
			},
		}
	}
</script>

<style scoped='scss'>
	.user-perfetion-page {
		padding: 30px 30rpx;
		box-sizing: border-box;
	}

	.foot {
		position: fixed;
		bottom: 0rpx;
		left: 0px;
		width: 100%;
		height: 150rpx;
		background: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.submit {
		width: 600rpx;
		height: 92rpx;
		background: #17BF8B;
		border-radius: 46rpx;
		color: #fff;
	}

	.input {
		/* border-color: rgb(229, 229, 229); */
		background-color: rgb(255, 255, 255);
		border: 1px solid rgb(229, 229, 229);
		height: 70rpx;
		padding: 0px 10rpx;
		line-height: 70rpx;
		color: #666;
		border-radius: 10rpx;
	}
</style>